#!/bin/bash

# MySQL性能监控脚本

MASTER_HOST="mysql-master"

echo "=== MySQL性能监控 ==="
echo "检查时间: $(date)"
echo

# 连接数
echo "当前连接数:"
docker exec $MASTER_HOST mysql -u root -proot123 -e "SHOW STATUS LIKE 'Threads_connected';"

# 查询统计
echo -e "\n查询统计:"
docker exec $MASTER_HOST mysql -u root -proot123 -e "SHOW STATUS LIKE 'Questions';"
docker exec $MASTER_HOST mysql -u root -proot123 -e "SHOW STATUS LIKE 'Slow_queries';"

# InnoDB状态
echo -e "\nInnoDB状态:"
docker exec $MASTER_HOST mysql -u root -proot123 -e "SHOW ENGINE INNODB STATUS\G" | grep -E "(Buffer pool hit rate|Log sequence number|Last checkpoint at)"
